package com.ruoyi.web.controller.app;

import com.ruoyi.business.domain.WmsDeliveryRecord;
import com.ruoyi.business.domain.WmsDeliveryRecordDetail;
import com.ruoyi.business.service.IWmsDeliveryRecordDetailService;
import com.ruoyi.business.service.IWmsDeliveryRecordService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 出库单Controller
 *
 * @author ruoyi
 * @date 2024-01-13
 */
@RestController
@RequestMapping("/app/deliveryRecord")
public class DeliveryRecordController extends BaseController
{
    @Autowired
    private IWmsDeliveryRecordService wmsDeliveryRecordService;

    @Autowired
    private IWmsDeliveryRecordDetailService wmsDeliveryRecordDetailService;

//    /**
//     * 查询出库单列表
//     */
//    @GetMapping("/list")
//    public TableDataInfo list(WmsDeliveryRecord wmsDeliveryRecord)
//    {
//        startPage();
//        List<WmsDeliveryRecord> list = wmsDeliveryRecordService.selectWmsDeliveryRecordList(wmsDeliveryRecord);
//        return getDataTable(list);
//    }
//
//    /**
//     * 导出出库单列表
//     */
//    @Log(title = "出库单", businessType = BusinessType.EXPORT)
//    @GetMapping("/export")
//    public AjaxResult export(WmsDeliveryRecord wmsDeliveryRecord)
//    {
//        List<WmsDeliveryRecord> list = wmsDeliveryRecordService.selectWmsDeliveryRecordList(wmsDeliveryRecord);
//        ExcelUtil<WmsDeliveryRecord> util = new ExcelUtil<WmsDeliveryRecord>(WmsDeliveryRecord.class);
//        return util.exportExcel(list, "出库单数据");
//    }

    /**
     * 获取出库单详细信息
     */
    @GetMapping(value = "/{deliveryNo}")
    public AjaxResult getInfo(@PathVariable("deliveryNo") String deliveryNo)
    {
        return AjaxResult.success(wmsDeliveryRecordService.selectWmsDeliveryRecordByDeliveryNo(deliveryNo));
    }
//
//    /**
//     * 新增出库单
//     */
//    @Log(title = "出库单", businessType = BusinessType.INSERT)
//    @PostMapping
//    public AjaxResult add(@RequestBody WmsDeliveryRecord wmsDeliveryRecord)
//    {
//        return toAjax(wmsDeliveryRecordService.insertWmsDeliveryRecord(wmsDeliveryRecord));
//    }
//
//    /**
//     * 修改出库单
//     */
//    @Log(title = "出库单", businessType = BusinessType.UPDATE)
//    @PutMapping
//    public AjaxResult edit(@RequestBody WmsDeliveryRecord wmsDeliveryRecord)
//    {
//        WmsDeliveryRecord into = new WmsDeliveryRecord();
//        into.setId(wmsDeliveryRecord.getId());
//        String deliveryTruck = wmsDeliveryRecord.getDeliveryTruck();
//        if (deliveryTruck == null) {
//            deliveryTruck = "";
//        }
//        into.setDeliveryTruck(deliveryTruck);
//        into.setUpdateBy(getUsername());
//        return toAjax(wmsDeliveryRecordService.updateWmsDeliveryRecord(into));
//    }

//    /**
//     * 删除出库单
//     */
//    @Log(title = "出库单", businessType = BusinessType.DELETE)
//	@DeleteMapping("/{ids}")
//    public AjaxResult remove(@PathVariable Long[] ids)
//    {
//        return toAjax(wmsDeliveryRecordService.deleteWmsDeliveryRecordByIds(ids));
//    }

    @GetMapping("/queryDetail")
    public AjaxResult query(WmsDeliveryRecordDetail wmsDeliveryRecordDetail)
    {
        List<WmsDeliveryRecordDetail> list = wmsDeliveryRecordDetailService.selectWmsDeliveryRecordDetailList(wmsDeliveryRecordDetail);
        return AjaxResult.success(list);
    }

    /**
     * 修改出库单货物信息
     */
    @Log(title = "货物出库", businessType = BusinessType.UPDATE)
    @PutMapping("detail")
    public AjaxResult edit(@RequestBody WmsDeliveryRecordDetail wmsDeliveryRecordDetail)
    {
        wmsDeliveryRecordDetail.setUpdateBy(getUsername());
        return toAjax(wmsDeliveryRecordDetailService.updateWmsDeliveryRecordDetail(wmsDeliveryRecordDetail));
    }
}
